/* eslint-disable no-unused-vars */
import router from '@/router';
import store from '@/store';
import storage from 'store';
import NProgress from 'nprogress'; // progress bar
import '@/components/NProgress/nprogress.less'; // progress bar custom style
NProgress.configure({ showSpinner: false }); // NProgress Configuration
const loginPath = '/login';
const homePath = '/';
const whiteList = [loginPath];
router.beforeEach((to, from, next) => {
  NProgress.start();
  next();

  // if (storage.get('ACCESS_TOKEN')) {
  //   if (to.path === loginPath) {
  //     next({ path: homePath });
  //   } else {
  //     next();
  //     // const redirect = decodeURIComponent(from.query.redirect || to.path);
  //     // if (to.path === redirect) {
  //     //   next({ ...to, replace: true });
  //     // } else {
  //     //   next({ path: redirect });
  //     // }
  //   }
  // } else {
  //   if (whiteList.includes(to.path)) {
  //     next();
  //   } else {
  //     store.dispatch('logout');
  //     next({ path: loginPath, query: { redirect: to.fullPath } });
  //   }
  // }
});

router.afterEach(() => {
  NProgress.done();
});
